//
//  WenXianCanKaoListViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/12.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "WenXianCanKaoListViewController.h"

@interface WenXianCanKaoListViewController ()

@property (nonatomic, strong) NSMutableArray *wenXianArray; // 参考文献的数组

@property (nonatomic, strong) UIScrollView *backGroundView; // 背景

@end

@implementation WenXianCanKaoListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 添加数据源
    [self addData];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    self.navigationItem.title = @"文献参照表";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 添加数据源
- (void)addData
{
   self.wenXianArray = [NSMutableArray arrayWithObjects:@"Li Y, et al. Quantitative assessment of the effect of ABCA1 R219K polymorphism on the risk of coronary heart disease. Mol Biol Rep. 2012 Feb;39(2):1809-13. ", @"Prof Paul Elliott, et al. Genetic Loci Influencing C-reactive Protein Levels and Risk of Coronary Heart Disease. JAMA. 2009 Jul 1; 302(1): 37–48. ", @"Xiangfeng Lu, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease. Nature Genetics, VOLUME 44, NUMBER 8, AUGUST 2012.", @"Assimes, T.L. et al. Susceptibility locus for clinical and subclinical coronary artery disease at chromosome 9p21 in the multi-ethnic ADVANCE study. Hum. Mol. Genet. 17,2320–2328 (2008).", @"Xiangfeng Lu, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease. Nature Genetics, VOLUME 44, NUMBER 8, AUGUST 2012.", @"Zhou, L. et al. Associations between single nucleotide polymorphisms on chromosome 9p21 and risk of coronary heart disease in Chinese Han population. Arterioscler. Thromb. Vasc. Biol. 28, 2085–2089 (2008).", nil];
    
    
}

#pragma mark - 布局
- (void)addMySubview
{
//    CGFloat nextWenXianHeight = 0.0;
//    for (int i = 0; i < self.wenXianArray.count; i++) {
//        UIButton *wenXianButton = [UIButton buttonWithType:UIButtonTypeSystem];
//        wenXianButton.frame = CGRectMake((375 - 150) / 2 * kAdjustParamater, 45 * kAdjustParamater + nextWenXianHeight, 150 * kAdjustParamater, 40 * kAdjustParamater);
//        wenXianButton.backgroundColor = kCyanColor;
//        [wenXianButton setTitle:self.wenXianArray[i] forState:UIControlStateNormal];
//        [wenXianButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        wenXianButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k18Big];
//        [wenXianButton addTarget:self action:@selector(wenXian:) forControlEvents:UIControlEventTouchUpInside];
//        wenXianButton.tag = 200 + i;
//        wenXianButton.layer.cornerRadius = 5 * kAdjustParamater;
//        wenXianButton.layer.masksToBounds = YES;
//        [self.view addSubview:wenXianButton];
//        nextWenXianHeight = nextWenXianHeight + wenXianButton.height + 25 * kAdjustParamater;
//    }
    self.backGroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.backGroundView.backgroundColor = [UIColor whiteColor];
    self.backGroundView.bounces = NO;
    self.backGroundView.showsVerticalScrollIndicator = NO;
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, 1.1 * kAdjustParamater);
    [self.view addSubview:_backGroundView];
    
    // 记录下一个文献的开始位置
    CGFloat nextWenXianStartY = 0.0;
    
    // 进行动态的布局
    for (int i = 0; i < self.wenXianArray.count; i++) {
        // 文献前方的数字
        UILabel *wenXianNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 * kAdjustParamater, 30 * kAdjustParamater + nextWenXianStartY, 60 * kAdjustParamater, 25 * kAdjustParamater)];
        wenXianNumberLabel.backgroundColor = kCyanColor;
        wenXianNumberLabel.text = [NSString stringWithFormat:@"文献%d", i + 1];
        wenXianNumberLabel.textAlignment = NSTextAlignmentCenter;
        wenXianNumberLabel.textColor = [UIColor whiteColor];
        wenXianNumberLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k16Big];
        wenXianNumberLabel.layer.cornerRadius = 5 * kAdjustParamater;
        wenXianNumberLabel.layer.masksToBounds = YES;
        [self.backGroundView addSubview:wenXianNumberLabel];
        
        
        
        // 文献内容表
        UILabel *wenXianContentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 * kAdjustParamater, wenXianNumberLabel.bottom + 15 * kAdjustParamater, 340 * kAdjustParamater, 100 * kAdjustParamater)];
      //  wenXianContentLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        wenXianContentLabel.text = self.wenXianArray[i];
        wenXianContentLabel.textColor = [UIColor blackColor];
        wenXianContentLabel.font = [UIFont systemFontOfSize:k16Big];
        wenXianContentLabel.numberOfLines = 0;
        wenXianContentLabel.tag = 100 + i;
        // 调整行间距
        [wenXianContentLabel setAttributedText:[[NetStatusHandle shareHandle] setHangJianJvOfLabel:wenXianContentLabel.text lineHeight:10]];
        [wenXianContentLabel sizeToFit];
        [self.backGroundView addSubview:wenXianContentLabel];
        
        // 文献数字下方的灰色条
        UILabel *grayLineOnWenXianNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, wenXianContentLabel.bottom + 15 * kAdjustParamater, kScreenWidth, 10 * kAdjustParamater)];
        grayLineOnWenXianNumberLabel.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent:0.05];
        [self.backGroundView addSubview:grayLineOnWenXianNumberLabel];
        
        nextWenXianStartY = nextWenXianStartY + 15 * kAdjustParamater + 25 * kAdjustParamater + 10 * kAdjustParamater + wenXianContentLabel.height + 15 * kAdjustParamater + 15 * kAdjustParamater;
        
    }
    // 取出最后一个文献
    UILabel *contentLabel = (UILabel *)[self.view viewWithTag:99 + self.wenXianArray.count];
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, contentLabel.bottom + 50 * kAdjustParamater);
    
}

//#pragma mark -  点击文献
//- (void)wenXian:(UIButton *)button
//{
//    NSLog(@"点击了第%ld个文献", button.tag - 199);
//}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
